<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>查找指定字符在字符串中的最后一次出现</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.strpos.html">strpos</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.strrev.html">strrev</a></div>
 <div class="up"><a href="ref.strings.html">字符串函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.strrchr" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strrchr</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">strrchr</span> &mdash; <span class="dc-title">查找指定字符在字符串中的最后一次出现</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.strrchr-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>strrchr</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$haystack</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$needle</code></span>
   )</div>

  <p class="para rdfs-comment">
   该函数返回 <em><code class="parameter">haystack</code></em> 字符串中的一部分，这部分以 <em><code class="parameter">needle</code></em> 的最后出现位置开始，直到 <em><code class="parameter">haystack</code></em> 末尾。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strrchr-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">haystack</code></em></dt>

     <dd>

      <p class="para">
       在该字符串中查找。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">needle</code></em></dt>

     <dd>

      <p class="para">
       如果 <em><code class="parameter">needle</code></em> 包含了不止一个字符，那么仅使用第一个字符。该行为不同于 <span class="function"><a href="function.strstr.html" class="function">strstr()</a></span>。
      </p>
      <p class="para">
       如果 <em><code class="parameter">needle</code></em> 不是一个字符串，那么将被转化为整型并被视为字符顺序值。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strrchr-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   该函数返回字符串的一部分。如果 <em><code class="parameter">needle</code></em> 未被找到，返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.strrchr-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.3.0</td>
       <td>
        该函数是二进制安全的。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.strrchr-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4800">
    <p><strong>Example #1 <span class="function"><strong>strrchr()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;获取&nbsp;$PATH&nbsp;中不含磁盘符号的目录<br /></span><span style="color: #0000BB">$dir&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">strrchr</span><span style="color: #007700">(</span><span style="color: #0000BB">$PATH</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">":"</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;获取最后一行内容<br /></span><span style="color: #0000BB">$text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Line&nbsp;1\nLine&nbsp;2\nLine&nbsp;3"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$last&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">strrchr</span><span style="color: #007700">(</span><span style="color: #0000BB">$text</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">1&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>   
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.strrchr-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数可安全用于二进制对象。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strrchr-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.strstr.html" class="function" rel="rdfs-seeAlso">strstr()</a> - 查找字符串的首次出现</span></li>
    <li class="member"><span class="function"><a href="function.substr.html" class="function" rel="rdfs-seeAlso">substr()</a> - 返回字符串的子串</span></li>
    <li class="member"><span class="function"><a href="function.stristr.html" class="function" rel="rdfs-seeAlso">stristr()</a> - strstr 函数的忽略大小写版本</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.strpos.html">strpos</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.strrev.html">strrev</a></div>
 <div class="up"><a href="ref.strings.html">字符串函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
